package com.cdu.service.Impl;

import com.cdu.commons.PageR;
import com.cdu.mapper.FavoriteMapper;
import com.cdu.mapper.ProductMapper;
import com.cdu.pojo.dto.FavoriteDTO;
import com.cdu.pojo.dto.ProductPageQueryDTO;
import com.cdu.pojo.vo.ProductVO;
import com.cdu.service.ProductService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class ProductServiceImpl implements ProductService {

    private final ProductMapper productMapper;
    private final FavoriteMapper favoriteMapper;


    @Override
    public PageR page(ProductPageQueryDTO productPageQueryDTO) {
        //使用Mybatis分页插件
        PageHelper.startPage(productPageQueryDTO.getPage(), productPageQueryDTO.getPageSize());
        Page<ProductVO> page=productMapper.pageQuery(productPageQueryDTO);
        return new PageR(page.getTotal(),page.getResult());
    }

    @Override
    public void favorite(FavoriteDTO favoriteDTO) {
        favoriteMapper.save(favoriteDTO);
    }
}
